<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Linux基线检查</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f9fbfc;
        }

        h2 {
            width: 445px;
            background-color: #0096c7;
            color: white;
            height: 50px;
            border-radius: 5px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
            text-align: center;
            line-height: 50px;
            font-weight: bold;
            margin-top: 30px;
            margin: 0 auto;
        }

        form {
            width: 400px;
            margin: 0 auto;
            background-color: #fff;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }

        input[type="text"],
        input[type="password"] {
            width: 95%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 3px;
        }

        input[type="submit"] {
            background-color: #0096c7;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 3px;
            cursor: pointer;
            display: block;
            margin: 0 auto;
            margin-top: 10px;
        }
    </style>
</head>
<body>
<div>
    <h2>Linux基线检查</h2>
    <br />
    <form id="linuxForm">
        <label for="ip">IP:</label>
        <input type="text" id="ip" class="input-field" /><br /><br />
        <label for="username">用户名:</label>
        <input type="text" id="username" class="input-field" /><br /><br />
        <label for="password">密码:</label>
        <input type="password" id="password" class="input-field" /><br /><br />
        <input type="submit" value="提交" class="submit-btn" />
    </form>
</div>

<script>
    document.getElementById('linuxForm').addEventListener('submit', function (event) {
        event.preventDefault(); // 阻止表单提交的默认行为

        const ip = document.getElementById('ip').value;
        const username = document.getElementById('username').value;
        const password = document.getElementById('password').value;

        // 检查输入是否为空
        if (!ip || !username || !password) {
            alert('请填写所有字段！');
            return;
        }

        // 跳转到结果页面（模拟跳转，替换为实际的 URL）
        window.location.href = "/jxjc_display.html";

        // 发送表单数据
        const formData = {
            ip: ip,
            username: username,
            password: password,
        };

        // 发起 POST 请求
        fetch("http://127.0.0.1:8081/submit", {
            method: "POST",
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(formData),
        })
            .then(response => response.json())
            .then(data => {
                console.log('Response:', data);
            })
            .catch(error => {
                console.error('Error:', error);
                alert('表单提交失败，网络错误。');
            });
    });
</script>
</body>
</html>
